package com.anpy.personal;


/**
 * @author 张超
 * @Description Servlet路径匹配器
 * @date 2019/5/21 11:41
 **/
public class ServletPathMatcher implements PatternMatcher {

    private static final ServletPathMatcher INSTANCE = new ServletPathMatcher();

    private ServletPathMatcher() {

    }

    public static ServletPathMatcher getInstance() {
        return INSTANCE;
    }

    @Override
    public boolean matches(String pattern, String source) {
        if (pattern != null && source != null) {
            pattern = pattern.trim();
            source = source.trim();

            if (pattern.endsWith("/**")) {
                pattern = pattern.substring(0,pattern.indexOf("/**"));
                if (source.contains(pattern)) {
                    return true;
                }
            }else if (pattern.equals(source)) {
                return true;
            }
            return false;
        } else {
            return false;
        }
    }
}
